home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Macintosh / Development & Resource Tools / MacsBug6.5.3.sit / MacsBug 6.5.3 / Building dcmds / C Samples / Drvr.c next >
Text File  |  1996-02-22  |  6KB  |  271 lines

  1. /*
  2.     File:        Drvr.c
  3.  
  4.     Contains:    This is the Unit Table dcmd.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglass
  9.  
  10.     Copyright:    © 1988,1993-1996 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <6>   25-Jan-96    JM3        Updated the sample build commands to be current.
  15.          <5>    10/27/95    DAL        Draw "-nil-" instead of empty-string for nil DRVR handles
  16.                                     (merged in from Scott Douglass' source).
  17.          <4>   10-Dec-94    JM3        Updated for new format 3 dcmd requirements.
  18.          <3>     3/14/94    DAL        Re-layed-out the columns: removed Window and made room for
  19.                                     everything to be nice on 13" monitors. Made the "that's strange"
  20.                                     message not show up for dRef = 0xFFFE (.Sony for HD-20). Now
  21.                                     Hoon is happy.
  22.          <2>     9/14/93    DAL        made the driver name column wider
  23.  
  24.     Modification history:
  25.          7Dec88 sad        show driver version
  26.         29Nov88 sad        revised for new dcmd names
  27.         13Oct88 sad        written from file.c
  28.  
  29.     The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
  30.     in the System folder. The dcmd's name in MacsBug will be the name of the file built by
  31.     the Linker.
  32.  
  33.     C Drvr.c
  34.     Link -o Drvr -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Put.c.o Drvr.c.o"    ∂
  35.         "{Libraries}Runtime.o"
  36.     BuildDcmd Drvr 193 -format3
  37.     Echo 'include "Drvr";'    |    Rez -a -o "{SystemFolder}Debugger Prefs"
  38.  
  39. */
  40.  
  41. #ifdef USESTDIO
  42.     #include <stdio.h>
  43. #endif
  44.  
  45. #include <Types.h>
  46. #include <Memory.h>
  47. #include <Devices.h>
  48. #include <SysEqu.h>
  49.  
  50. #include "dcmd.h"
  51. #include "put.h"
  52.  
  53.  
  54. typedef struct DRVR
  55. {
  56.     short drvrFlags;
  57.     short drvrDelay;
  58.     short drvrEMask;
  59.     short drvrMenu;
  60.     short drvrOpen;
  61.     short drvrPrime;
  62.     short drvrCtl;
  63.     short drvrStatus;
  64.     short drvrClose;
  65.     Str255 drvrName;
  66. } DRVR;
  67.  
  68.  
  69. static void DrawHdr()
  70. {
  71. //                    0         1         2         3         4         5         6         7         8         9
  72. //                    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
  73.     dcmdDrawLine("\pdRef dNum Driver                      Flg  Ver   qHead   Storage Dely  Drvr at DCE at");
  74. }
  75.  
  76. #define kColumnNameEnd         37
  77. #define kColumnVersionEnd    46
  78. #define kColumnQHeadEnd        54
  79. #define kColumnStorageEnd    64
  80. #define kColumnDriverAtEnd    78
  81. #define kColumnDCEAtEnd        85
  82.  
  83.  
  84. static void DrawDCE(int dref, AuxDCE* dcep)
  85. {
  86.     DRVR*    drvrp;
  87.  
  88.     PutUHexWord(dref);
  89.     PutSpace();
  90.     PutUHexWord(~dref);
  91.     PutSpace();
  92.     if (dcep->dCtlFlags & 0x40)
  93.     {
  94.         if (dcep->dCtlDriver)
  95.         {
  96.             drvrp = * (DRVR **) dcep->dCtlDriver;
  97.             if (drvrp)
  98.                 PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
  99.             else
  100.                 PutPStrTruncTo("\p-purged-", kColumnNameEnd);
  101.         }
  102.         else
  103.         {
  104.             PutPStrTruncTo("\p-nil-", kColumnNameEnd);
  105.         };
  106.     }
  107.     else
  108.     {
  109.         if (dcep->dCtlDriver)
  110.         {
  111.             drvrp = (DRVR*)dcep->dCtlDriver;
  112.             PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
  113.         }
  114.         else
  115.         {
  116.             PutPStrTruncTo("\p-nil-", kColumnNameEnd);
  117.         };
  118.     };
  119.     PutSpace();
  120.     PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
  121.     PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
  122.     PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
  123.     PutSpace();
  124.     PutUDecTo((unsigned char) dcep->dCtlQHdr.qFlags,kColumnVersionEnd);            // version
  125.     PutSpace();
  126.     PutUHexZTo((unsigned long) dcep->dCtlQHdr.qHead,8,kColumnQHeadEnd);            // qHead
  127.     PutSpace();
  128.     PutUHexZTo((unsigned long) dcep->dCtlStorage,8,kColumnStorageEnd);            // Storage
  129.     PutSpace();
  130.     PutUHexWord((unsigned long) dcep->dCtlDelay);
  131.     PutSpace();
  132.     PutUHexZTo((unsigned long) drvrp,8,kColumnDriverAtEnd);
  133.     PutSpace();
  134.     PutUHexZTo((unsigned long) dcep,8,kColumnDCEAtEnd);
  135.     PutLine();
  136.  
  137.     // For drvr FFFE (.Sony for the HD20, pre-SCSI), it's okay that
  138.     // the dCtlRefNum is $FFFB (don't whine about it)
  139.  
  140.     if ( (dref != dcep->dCtlRefNum) && ( ((unsigned short) dref) != (unsigned short) 0xFFFE) )
  141.     {
  142.         PutPStr("\p   that is strange:  dCtlRefNum = ");
  143.         PutUHexWord(dcep->dCtlRefNum);
  144.         PutLine();
  145.     }
  146. } // DrawDCE
  147.  
  148.  
  149. pascal void CommandEntry(dcmdBlock* paramPtr)
  150. {
  151.  
  152.     static const Str255 usageStr = "\p[refNum|num]";
  153.  
  154.     switch (paramPtr->request)
  155.     {
  156.         case dcmdInit:
  157.             break;
  158.  
  159.         case dcmdHelp:
  160.             dcmdDrawLine("\pDisplays driver information for the given refNum or all installed");
  161.             dcmdDrawLine("\pdrivers. Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
  162.             break;
  163.  
  164.         case dcmdGetInfo:
  165.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  166.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  167.             break;
  168.  
  169.         case dcmdDoIt:
  170.         {
  171.             Boolean doOne = false;
  172.             long dref;
  173.             int NumDCEs;
  174.  
  175.             dcmdSwapWorlds();
  176.  
  177.             dcmdDrawLine("\pDisplaying Driver Control Entries");
  178.  
  179.             // Get low-memory values after dcmdSwapWorlds().
  180.  
  181.             NumDCEs = *(unsigned short *)UnitNtryCnt;
  182.  
  183.             (void)dcmdGetNextExpression(&dref, &doOne);
  184.  
  185.             if (doOne)
  186.             {
  187.                 int dnum;
  188.                 dref = (short)dref;
  189.                 if (dref < 0)
  190.                     dnum = ~dref;
  191.                 else
  192.                 {
  193.                     dnum = dref;
  194.                     dref = ~dref;
  195.                 }
  196.                 if (dnum > NumDCEs)
  197.                 {
  198. #ifdef USESTDIO
  199.                     Str255 line;
  200.                     sprintf(line,"Bad refnum 0x%.4x",(unsigned short)dref);
  201.                     dcmdDrawLine((Str255)c2pstr(&line));
  202. #else
  203.                     PutPStr("\pBad refnum ");
  204.                     PutUHexWord(dref);
  205.                     PutSpace();
  206.                     PutUHexWord(~dref);
  207.                     PutLine();
  208. #endif
  209.                 }
  210.                 else
  211.                 {
  212.                     AuxDCE** dceh = (*(AuxDCE****)UTableBase)[dnum];
  213.                     if (dceh)
  214.                     {
  215.                         DrawHdr();
  216.                         DrawDCE(dref,*dceh);
  217.                     }
  218.                     else
  219.                     {
  220.                         PutPStr("\pDriver ");
  221.                         PutUHexWord(dref);
  222.                         PutSpace();
  223.                         PutUHexWord(~dref);
  224.                         PutPStr("\p is not in installed");
  225.                         PutLine();
  226.                     }
  227.                 }
  228.             }
  229.             else
  230.             {
  231.                 int DCEsUsed = 0;
  232.                 int dnum;
  233.                 AuxDCE*** dcehp;
  234.                 Boolean foundOne = false;
  235.                 for(dnum = 0, dcehp = *(AuxDCE****)UTableBase; dnum < NumDCEs; dnum++, dcehp++)
  236.                 {
  237.                     if (*dcehp)
  238.                     {
  239.                         DCEsUsed++;
  240.                         if (!foundOne)
  241.                         {
  242.                             DrawHdr();
  243.                             foundOne = true;
  244.                         }
  245.                         DrawDCE(~dnum,**dcehp);
  246.                     }
  247.                     if (paramPtr->aborted) break;
  248.                 }
  249.                 if(!paramPtr->aborted)
  250.                 {
  251.                     PutUDec(NumDCEs);
  252.                     PutPStr("\p Unit Table entries, ");
  253.                     PutUDec(DCEsUsed);
  254.                     PutPStr("\p in use, ");
  255.                     PutUDec(NumDCEs - DCEsUsed);
  256.                     PutPStr("\p free");
  257.                     PutLine();
  258.                 }
  259.             }    
  260.  
  261.             dcmdSwapWorlds();
  262.             break;
  263.         }
  264.  
  265.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  266.  
  267.         default:
  268.             break;
  269.     }
  270. }
  271.